
(define null (lambda (x) (eq x (quote ()))))

(define and (lambda (x y) (cond (x (cond (y (quote t)) ((quote t) (quote ()))))
				((quote t) (quote ())))))

(define or (lambda (x y) (cond (x (quote t)) (y (quote t)) ((quote t) (quote ())))))

(define not (lambda (x) (cond (x (quote ()))
			      ((quote t) (quote t)))))

(define append (lambda (x y) 
		 (cond ((null x) y)
		       ((quote t) (cons (car x) (append (cdr x) y))))))

(define list (lambda (x y) 
	      (cons x (cons y (quote ())))))

(define pair (lambda (x y) 
	       (cond ((and (null x) (null y)) (quote ()))
		      ((and (not (atom x)) (not (atom y)))
		       (cons (list (car x) (car y))
			     (pair (cdr x) (cdr y)))))))
(define caar (lambda (x) 
	       (car (car x))))

(define cadr (lambda (x)
	       (car (cdr x))))

(define cadar (lambda (x)
	       (car (cdr (car x)))))

(define assoc (lambda (x y)
		(cond ((eq (caar y) x) (cadar y))
		      ((quote t) (assoc x (cdr y))))))

(define caddar (lambda (x)
		 (car (cdr (cdr (car x))))))

(define caddr (lambda (x)
		(car (cdr (cdr x)))))

(define eval (lambda (x y)
	       (cond 
		 ((atom x) (assoc x y))
		 ((atom (car x))
		  (cond
		    ((eq (car x) (quote quote)) (car (cdr x)))
		    ((eq (car x) (quote atom)) (atom (eval (cadr x) y)))
		    ((eq (car x) (quote eq)) (eq (eval (cadr x) y)
						 (eval (caddr x) y)))
		    ((eq (car x) (quote car)) (car (eval (cadr x) y)))
		    ((eq (car x) (quote cdr)) (cdr (eval (cadr x) y)))
		    ((eq (car x) (quote cons)) (cons (eval (cadr x) y)
						     (eval (caddr x) y)))
		    ((eq (car x) (quote cond)) (evcon (cdr x) y))
		    ((quote t) (eval (cons (assoc (car x) y)
					   (cdr y))
				     y))))
		 ((eq (caar x) (quote label))
		  (eval (cons (caddar x) (cdr x))
			(cons (list (cadar x) (car x)) y)))
		 ((eq (caar x) (quote lambda))
		  (eval (caddar x)
			(append (pair (cadar x) (evlis (cdr x) y))
				y))))))



(define evlis (lambda (x y)
		(cond ((null x) (quote ()))
		      ((quote t) (cons (eval (car x) y)
				       (evlis (cdr x) y))))))



(define evcon (lambda (c a)
		(cond ((eval (caar c) a)
		       (eval (cadar c) a))
		      ((quote t) (evcon (cdr c) a))
		      )))



(eval (quote ((lambda (ee) (car (cdr ee))) (quote (a b c)))) (quote ()))

(define 1 (lambda (x) (quote t)))

(define 0 (lambda (x) (quote ())))

(define _addtion_table (lambda (x y) 
			 (cond  ((and x y)
				(quote (t ())))
				((or x y)
				 (quote (() t)))
				((quote t)
				 (quote (() ()))))))

(0)
(1)
(or (0) (1))
(_addtion_table (0) (1))
(_addtion_table (1) (1))
(_addtion_table (1) (0))
(_addtion_table (0) (0))

(define _hex_table (lambda (x)
		     (cond ((eq x (quote 0))
			    (quote (() () () ())))
			   ((eq x (quote 1))
			    (quote (t () () ())))
			   ((eq x (quote 2))
			    (quote (() t () ())))
			   ((eq x (quote 3))
			    (quote (t t () ())))
			   ((eq x (quote 4))
			    (quote (() () t ())))
			   ((eq x (quote 5))
			    (quote (t () t ())))
			   ((eq x (quote 6))
			    (quote (() t t ())))
			   ((eq x (quote 7))
			    (quote (t t t () )))
			   ((eq x (quote 8))
			    (quote (() () () t )))
			   ((eq x (quote 9))
			    (quote ( t () () t)))
			   ((eq x (quote a))
			    (quote (() t () t)))
			   ((eq x (quote b))
			    (quote (t t () t)))
			   ((eq x (quote c))
			    (quote (() () t t)))
			   ((eq x (quote d))
			    (quote (t () t t)))
			   ((eq x (quote e))
			    (quote (() t t t)))
			   ((eq x (quote f))
			    (quote (t t t t)))
			   ((null x)
			    (quote ())))))




(define hex (lambda (x) 
	      (cond ((null x) (quote ()))
		    ((quote t) 
		     (append (_hex_table (car x)) (hex (cdr x)))))))

(define _add (lambda (x y z)
	       (cond ((and (null x) (null y)) (cons z (quote ()))) 
		     ((quote t)
		      (cond 
			(z 
			 (cond 
			   ((car (_addtion_table (car x) (car y)))
			    (cons (quote t) (_add (cdr x) (cdr y) (quote t))))
			   ((cadr (_addtion_table (car x) (car y)))
			    (cons (quote ()) (_add (cdr x) (cdr y) (quote t))))
			   ((quote t)
			    (cons (quote t) (_add (cdr x) (cdr y) (quote ()))))))
			((quote t)
			 (cons (cadr (_addtion_table (car x) (car y)))
			       (_add (cdr x) (cdr y) (car (_addtion_table (car x) (car y)))))))))))


(define _reverse (lambda (x)
		   (cond ((null (cdr x))
			  (cons (not (car x)) (quote ())))
			 ((quote t)
			  (cons (not (car x)) (_reverse (cdr x)))))))

(define _complement (lambda (x) 
			(_add (_reverse x) (quote (t)) (quote ()))))

(echo (_reverse (quote (() t () () ))))

(echo (_complement (_complement (quote (() t () ())))))

(echo (_add (hex (quote (3 4 5) )) (quote (t t t () t t t)) (quote t)) )


